<template>
  <el-upload
    class="upload-demo"
    action="/manage/upload"
    :on-success="handleChange"
    :file-list="value"
    v-bind="mergeConfig"
  >
    <el-button size="small" type="primary">上传</el-button>
    <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div> -->
  </el-upload>
</template>

<script>
export default {
  props: {
    value: {
      type: [Array],
      default() {
        return []
      }
    },
    config: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      defaultConfig: {
        limit: 1
      }
    }
  },
  computed: {
    mergeConfig() {
      const config = Object.assign(this.config, this.defaultConfig)
      return config
    }
  },
  methods: {
    idArray(value) {
      return Array.isArray(value)
    },
    handleChange(res, file, fileList) {
      const arr = [
        {
          name: res.data.fileName,
          url: res.data.filePath
        }
      ]
      this.$emit('input', arr)
    }
  }
}
</script>

<style></style>
